package com.jiyinit.web.core.common.timed;

/**
 * Created by Jiyinuser071 on 2018/12/20.
 */

import com.jiyinit.core.framework.base.util.LogUtil;
import com.jiyinit.web.core.activiti.controller.LeaveController;
import com.jiyinit.web.core.activiti.service.LeaveBillInfoServiceImpl;
import com.jiyinit.web.core.activiti.service.LeaveDealMindServiceImpl;
import com.jiyinit.web.core.activiti.service.LeaveDealServiceImpl;
import com.jiyinit.web.core.activiti.service.UserMemershipServiceImpl;
import com.jiyinit.web.core.business.entity.TabCoreTask;
import com.jiyinit.web.core.business.service.DictItemServiceImpl;
import com.jiyinit.web.core.business.service.OrgServiceImpl;
import com.jiyinit.web.core.business.service.TaskServiceImpl;
import com.jiyinit.web.core.business.service.UserServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 定时任务，将新注册简单任务人员加入到交流园地参与人列表
 * @author lichangqin
 * @create 2018/12/20 18:50
 */
@Component("exchangeGardenJob")
public class ExchangeGardenJob {

    private static Logger logger = LoggerFactory.getLogger(LeaveController.class);

    @Resource(name = "core.userServiceImpl")
    private UserServiceImpl userService;

    @Resource(name = "core.orgServiceImpl")
    OrgServiceImpl orgService;

    @Resource(name = "core.taskServiceImpl")
    private TaskServiceImpl taskService;

    public void execute() throws Exception{
        LogUtil.info(logger, "定时器任务开始...");
        try{
            List<TabCoreTask> taskList=taskService.findTaskIdByTaskCla();
            for (int i=0;i<taskList.size();i++){
                int createUid=taskList.get(i).getCreateUid();
                int taskId =taskList.get(i).getTaskId();
                int orgId=userService.getUserInfoByUserId(createUid).getOrgId();
                int parentOrgId=orgService.getTopParentOrgId(orgId);
                TabCoreTask coreTask=new TabCoreTask();
                coreTask.setCreateUid(createUid);
                int res= taskService.insertUserTimed(coreTask);
            }
        }
        catch (Exception e) {
            LogUtil.error(logger, "插入交流园地参与人定时任务出现异常");
            e.printStackTrace();
            throw e;
        }
        LogUtil.info(logger,"处理结束...");
    }
}
